using ASP;
using HoWave.Web;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.IO;
using System.Text;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Shop_Auction_request_item_detail : Shop, IRequiresSessionState
{
	public int m_lefttime = 0;
	public string PUnit = "";
	public int m_salerid = 0;
	public string ClassID = "0";
	public int RequestID = 0;
	protected Literal product_name;
	protected Image product_image;
	protected HtmlAnchor Showproduct_image;
	protected Literal product_price;
	protected Literal product_hits;
	protected Literal product_num;
	protected Literal product_place;
	protected Literal product_status;
	protected Literal DiscountLabel;
	protected HyperLink shop_ownername;
	protected Shop_UserControls_QQTaobaoContactMe ConectMe1;
	protected Shop_UserControls_ShowMemberIdentify ShowMemberIdentify1;
	protected HyperLink shop_saler_credit;
	protected HyperLink shop_buyer_credit;
	protected Literal saler_reg_date;
	protected HyperLink GoToShop;
	protected Label Product_CreateDate;
	protected Label Product_EndDate;
	protected Label product_intro;
	protected Label Product_Remark;
	protected HyperLink userlogin;
	protected Panel Message_Panel1;
	protected Label GuestBook;
	protected TextBox Message_Content;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected RequiredFieldValidator RequiredFieldValidator2;
	protected Label err_tips;
	protected TextBox CheckCode;
	protected Button Button1;
	protected Panel Message_Panel2;
	protected HiddenField h_product_id;
	protected HiddenField h_product_price;
	protected HiddenField h_productname;
	protected HiddenField h_shop_id;
	protected HiddenField h_saler_nickname;
	protected HiddenField h_saler_id;
	protected HiddenField h_ClassID;
	protected HtmlForm aspnetForm;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_PreInit(object sender, EventArgs e)
	{
		try
		{
			Template.BindTemplateToPage(this.Page, "RequestDetail");
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		base.ShowCityArea();
		if (base.Request["RequestID"] != null && base.Request["RequestID"] != "")
		{
			this.RequestID = Convert.ToInt32(base.Request.QueryString["RequestID"]);
		}
		if (!base.IsPostBack)
		{
			if (this.RequestID == 0)
			{
				base.Response.Write("对不起，没有你所要请求的求购商品");
				base.Response.End();
			}
			this.h_product_id.Value = this.RequestID.ToString();
			Shop_Request shop_Request = new Shop_Request();
			DataTable requestByID = shop_Request.GetRequestByID(this.RequestID);
			if (requestByID.Rows.Count == 0)
			{
				base.Response.Write("对不起，找不到你所要请求的求购商品数据");
				base.Response.End();
			}
			this.m_lefttime = Convert.ToInt32(requestByID.Rows[0]["LeftTime"]);
			if (this.m_lefttime < 0)
			{
				this.m_lefttime = 0;
			}
			this.m_salerid = int.Parse(requestByID.Rows[0]["RequesterID"].ToString());
			this.product_name.Text = requestByID.Rows[0]["RequestTitle"].ToString();
			this.product_image.Attributes.Add("onload", "ResizeImage(this,200,200)");
			if (requestByID.Rows[0]["UploadImageUrl"].ToString() == "" && !File.Exists(base.Server.MapPath("") + "//" + requestByID.Rows[0]["UploadImageUrl"].ToString()))
			{
				this.Showproduct_image.HRef = (this.product_image.ImageUrl = "Images/nopicture.gif");
			}
			else
			{
				this.Showproduct_image.HRef = (this.product_image.ImageUrl = requestByID.Rows[0]["UploadImageUrl"].ToString());
			}
			this.ClassID = requestByID.Rows[0]["RequestCategoryID"].ToString();
			this.h_ClassID.Value = this.ClassID.ToString();
			this.product_place.Text = requestByID.Rows[0]["RequestPlace"].ToString();
			this.product_num.Text = requestByID.Rows[0]["RequestNumber"].ToString();
			this.product_hits.Text = requestByID.Rows[0]["RequestClick"].ToString();
			this.product_intro.Text = requestByID.Rows[0]["Description"].ToString();
			this.product_price.Text = requestByID.Rows[0]["Price"].ToString();
			this.Product_Remark.Text = requestByID.Rows[0]["Remark"].ToString();
			this.Product_CreateDate.Text = "开始时间：" + requestByID.Rows[0]["CreateDate"].ToString();
			this.Product_EndDate.Text = "结束时间：" + requestByID.Rows[0]["EndDate"].ToString();
			this.PUnit = requestByID.Rows[0]["Unit"].ToString();
			this.userlogin.NavigateUrl = "Passport/Login.aspx?ComeUrl=" + this.Page.Request.Url.ToString();
			this.h_product_id.Value = this.RequestID.ToString();
			this.h_product_price.Value = this.product_price.Text;
			this.h_productname.Value = this.product_name.Text;
			this.h_saler_id.Value = this.m_salerid.ToString();
			if (base.user != null)
			{
				if (base.user.UserID == this.m_salerid)
				{
					this.GuestBook.Text = "向所有买家留言";
				}
				else
				{
					this.GuestBook.Text = "向求购者买家留言";
				}
			}
			UserInfoBll userInfoBll = new UserInfoBll();
			DataTable dataTable = new DataTable();
			dataTable = userInfoBll.GetShopUserBaseInfoByUserID(this.m_salerid);
			this.ConectMe1.UserID = this.m_salerid;
			if (base.user.UserID > 0)
			{
				int num = Convert.ToInt32(dataTable.Rows[0]["ShopID"].ToString());
				if (num > 0)
				{
					this.GoToShop.NavigateUrl = "Shop/" + dataTable.Rows[0]["ShopID"].ToString();
					this.h_shop_id.Value = num.ToString();
				}
				else
				{
					this.GoToShop.NavigateUrl = "Shop/" + this.m_salerid;
				}
				this.shop_ownername.Text = dataTable.Rows[0]["UserName"].ToString();
				this.h_saler_nickname.Value = this.shop_ownername.Text;
				this.shop_ownername.NavigateUrl = "Shop/" + this.m_salerid;
				this.shop_saler_credit.Text = string.Concat(new object[]
				{
					dataTable.Rows[0]["SaleCrediet"].ToString(),
					"&nbsp;<script type='text/javascript'>displayStar(",
					Convert.ToInt32(dataTable.Rows[0]["SaleCrediet"]),
					")</script>"
				});
				this.shop_saler_credit.NavigateUrl = (this.shop_buyer_credit.NavigateUrl = "Shop/" + this.m_salerid);
				this.shop_buyer_credit.Text = string.Concat(new object[]
				{
					dataTable.Rows[0]["BuyCrediet"].ToString(),
					"&nbsp;<script type='text/javascript'>displayStar(",
					Convert.ToInt32(dataTable.Rows[0]["BuyCrediet"]),
					")</script>"
				});
				this.ShowMemberIdentify1.PersonIdentify = dataTable.Rows[0]["AuthenticationType"].ToString();
				this.ShowMemberIdentify1.CompanyIdentify = dataTable.Rows[0]["CompanyIdentify"].ToString();
				this.ShowMemberIdentify1.MobileIdentify = dataTable.Rows[0]["MobileIdentify"].ToString();
				this.ShowMemberIdentify1.BandShopIdentify = dataTable.Rows[0]["BandShopIdentify"].ToString();
				this.ShowMemberIdentify1.PrePayIdentify = dataTable.Rows[0]["OtherIdentify1"].ToString();
				this.saler_reg_date.Text = dataTable.Rows[0]["RegTime"].ToString();
			}
			this.Message_Content.Attributes.Add("onClick", "displayMessageBtn();");
			shop_Request.UpdateRequestClick(this.RequestID);
			if (base.user != null)
			{
				this.Message_Panel1.Visible = false;
				this.Message_Panel2.Visible = true;
			}
		}
	}
	protected void LeaveMessage(object sender, EventArgs e)
	{
		if (this.CheckValidateCode())
		{
			int m_ShopID = 0;
			int m_ReceiverID = 0;
			int m_ProductID = 0;
			string m_UserType = "saler";
			string text = this.Message_Content.Text;
			if (base.user != null && text != "" && base.user.UserName != "")
			{
				int userID = base.user.UserID;
				if (this.h_shop_id.Value != "")
				{
					m_ShopID = Convert.ToInt32(this.h_shop_id.Value);
				}
				if (this.h_product_id.Value != "")
				{
					m_ProductID = Convert.ToInt32(this.h_product_id.Value);
				}
				if (this.h_saler_id.Value != "")
				{
					m_ReceiverID = Convert.ToInt32(this.h_saler_id.Value);
				}
				if (base.user.UserID == this.m_salerid)
				{
					m_UserType = "buyer";
				}
				Shop_Message shop_Message = new Shop_Message();
				text = base.Server.HtmlEncode(text);
				shop_Message.InsertMessage(2, m_ProductID, m_ShopID, userID, false, text, base.user.UserName, m_ReceiverID, this.h_saler_nickname.Value, m_UserType, this.RequestID);
				base.Response.Write("<script>alert('留言成功!');history.go(-1);</script>");
				base.Response.End();
			}
		}
		else
		{
			base.Response.Write("<script>alert('验证码出错!请重新填写！');history.go(-1);</script>");
			base.Response.End();
		}
	}
	public bool CheckValidateCode()
	{
		return string.Compare(this.Session["CheckCode"].ToString(), this.CheckCode.Text, true) == 0;
	}
	public void ShowEidtProudctLink()
	{
		string s = "<a href=\"Member/Shop_Complain.aspx?type=myRequest&RequestID=" + this.RequestID.ToString() + "\">举报该求购商品</a>";
		if (base.user != null)
		{
			if (base.user.UserID == this.m_salerid)
			{
				s = "<a href=\"shop_request_productEdit.aspx?RequestProductID=" + this.RequestID.ToString() + "\">编辑</a>";
			}
		}
		base.Response.Write(s);
	}
	protected void BandRequest_Class(string ClassID)
	{
		Shop_Class shop_Class = new Shop_Class();
		DataTable classMapPathByParentID = shop_Class.GetClassMapPathByParentID(int.Parse(ClassID));
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append("<ul class=\"PathLinks\">");
		stringBuilder.Append("  <li><a href=\"CategoryList.aspx\" target='_self'>所有分类</a></li>");
		if (classMapPathByParentID.Rows.Count > 0)
		{
			for (int i = 0; i < classMapPathByParentID.Rows.Count; i++)
			{
				stringBuilder.Append(string.Concat(new string[]
				{
					"<li><a href=\"Browse_Offer.aspx?ClassID=",
					classMapPathByParentID.Rows[i]["ClassID"].ToString(),
					"\">",
					classMapPathByParentID.Rows[i]["ClassName"].ToString(),
					"</a></li>"
				}));
			}
		}
		stringBuilder.Append("</ul>");
		base.Response.Write(stringBuilder.ToString());
	}
}
